package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.custom.BlueLoadingProgress;

public class SanPinChaXunDetailActivity extends Activity implements
		OnClickListener {

	// private EditText edtChaXunFilter = null;

	private TextView tvTitle = null;

	private ViewGroup btnBack = null;

	private ViewGroup btnRefresh = null;

	// private ViewGroup btnSearch = null;

	private BlueLoadingProgress blpLoading = null;

	private WebView wvChaXun = null;

	private String url = "";

	private String text = null;

	@Override
	protected void onDestroy() {

		InitApplication initApplication = (InitApplication) getApplicationContext();

		initApplication.getActivities().remove(this);

		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		InitApplication initApplication = (InitApplication) getApplicationContext();

		initApplication.getActivities().add(this);

		setContentView(R.layout.sanpin_chaxun_detail);

		url = getIntent().getStringExtra("url");

		text = getIntent().getStringExtra("text");

		String title = getIntent().getStringExtra("title");

		tvTitle = (TextView) findViewById(R.id.tvTitle);

		btnBack = (ViewGroup) findViewById(R.id.btnBack);

		btnRefresh = (ViewGroup) findViewById(R.id.btnRefresh);

		// btnSearch = (ViewGroup) findViewById(R.id.btnSearch);

		btnBack.setOnClickListener(this);
		btnRefresh.setOnClickListener(this);
		// btnSearch.setOnClickListener(this);

		// edtChaXunFilter = (EditText) findViewById(R.id.edtChaXunFilter);
		//
		// edtChaXunFilter.setHint(hint);
		//
		// edtChaXunFilter.setText(text);

		tvTitle.setText(title);

		blpLoading = (BlueLoadingProgress) findViewById(R.id.blpLoading);
		blpLoading.setVisibility(View.GONE);

		wvChaXun = (WebView) findViewById(R.id.wvChaXun);

		// 自动加载图片
		wvChaXun.getSettings().setLoadsImagesAutomatically(true);
		// 启用脚本
		wvChaXun.getSettings().setJavaScriptEnabled(true);

		wvChaXun.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageFinished(WebView view, String url) {

				if (blpLoading != null) {

					blpLoading.stopLoading();

					blpLoading.setVisibility(View.GONE);
				}

			}
		});

		blpLoading.setVisibility(View.VISIBLE);

		String url = SanPinChaXunDetailActivity.this.url + text;

		blpLoading.setVisibility(View.VISIBLE);

		wvChaXun.loadUrl(url);

	}

	@Override
	public void onClick(View v) {

		if (v == btnBack) {

			finish();
		}

		if (btnRefresh == v) {

			blpLoading.setVisibility(View.VISIBLE);

			blpLoading.setVisibility(View.VISIBLE);

			wvChaXun.reload();

		}

	}
}
